package com.jstide.credit.data.service.biz;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import com.jstide.credit.data.service.Algorithm;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.util.Date;
import java.util.List;
import java.util.Optional;

public class Factor28 extends Algorithm {

    private static final Logger logger = LoggerFactory.getLogger(Factor28.class);

    @Getter
    public final  String name="28";

    //其他不良信用信息
    //“一般”-20；“较重”-60；“严重”-80；一般、较重取1年内，严重取3年
    //-80
    @Getter
    public  final String sql =" select SXYZCD,RDRQ from  ZRRQTBLXYXX where join_id=@joinId  order by RDRQ asc ";

    @Override
    public int translate(String rs) {
        return 0;
    }

    @Override
    public int translate(List<Entity> rs) {
        int score = 0;
        if(null!=rs && rs.size()>0){
            try {
                for(Entity t : rs){
                    Date rq = t.getDate("RDRQ" );
                    String cd = t.getStr("SXYZCD");
                    if(null!=rq){
                        int year = DateUtil.ageOfNow(rq);
                        if(year< 3 ){
                            if(StrUtil.equals("严重",cd)){
                                return -80;
                            }
                            else if(year <1){
                                if( StrUtil.equals("一般",cd)){
                                    return  -20;
                                }
                                else if(StrUtil.equals("较重",cd)){
                                    return -60;
                                }
                                else{
                                }
                            }
                        }
                    }
                }
            }catch (Exception e){
                score=0;
            }
        }
        return score;
    }
}
